import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
    state: {
        menuList:[],
        permList: [],
        hasRouter:false,
        editableTabsValue: 'Index',
        editableTabs: [{
            title: '首页',
            name: 'Index',
        }]
    },
    mutations: {
        //  拿到用户权限
        setPermList(state,perm){
            state.permList=perm;
        },
        //  拿到menuList
        setMenuList(state,menus){
            state.menuList=menus;
        },
        changeRouteStatus(state,hasRouter){
            state.hasRouter=hasRouter
        },
        //添加tab标签
        addTab(state,tab){
            let index = state.editableTabs.findIndex(function (e) {
                if (e.name===tab.name){
                    return 1;
                }else {
                    return;
                }
            });
            if (index===-1){
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name,
                });
            }
            state.editableTabsValue =tab.name;
        },
        //退出重置用户状态
        resetState:(state)=>{
            state.permList=[];
            state.menuList=[];
            state.hasRouter=false;
            state.editableTabsValue='Index';
            state.editableTabs=[{
                title: '首页',
                name: 'Index',
            }]
        }
    },
    actions: {
    }
}
